<?php
/**
 * Category
 *
 * PHP version 5
 *
 * @category Controller
 * @version  1.0
 * @author   Duonght <hduongdmit@gmail.com>
 */
App::uses('AppController', 'Controller');
class ConfigurationController extends AppController {

	public $uses = 'Configuration';

	public function index(){
		$results = $this->Configuration->find('all', array(
					'fields' => '*',
					'conditions' => array('id' => 1),
					'order' => array('id DESC'),
					'limit' => 1,
			));

		$detail = reset($results);
		if ($this->request->is('post')) {
			$params = $this->request->data;
			if ($this->Configuration->save($params)) {

				$results = $this->Configuration->find('all', array(
						'fields' => '*',
						'conditions' => array('id' => 1),
						'order' => array('id DESC'),
						'limit' => 1,
				));
				$detail = reset($results);

				$this->Session->setFlash(__('Success'), 'success');

			} else {
				$this->Session->setFlash(__('Save could not be saved. Please, try again'), 'error');
			}
		}

		//forward to view layout
		$this->set(array(
				'detail' => $detail,
				'title_for_layout' => 'Thông tin văn phòng công chứng Âu Lạc',
		));

	}
}
